//无实体上传需要的action
try{
	var picStoreAction = ctx+"attachment/media/upload.action?isRemote=F";
}catch(e){
	alert("请在引入此js页面中定义一个ctx变量，此变量值为当前项目路径！谢谢");
}
function Supload(myPos,idname,fileType,imgW,imgH,sImgH,sImgW,callback){
	 if($("#sampleUW")){
		$("#sampleUW").replaceWith("");
	}
	
 var mydom = "<div id=\"sampleUW\" class=\"easyui-window\" iconCls=\"icon-ok\">" +
			 	"<div class=\"easyui-layout\" fit=\"true\">"+
			 		"<form target=\"uploadIframe\" name=\"uploadMedia\" id=\"uploadMedia\" action=\""+picStoreAction+"\" method=\"POST\" enctype=\"multipart/form-data\">"+
			 			"<input type=\"hidden\"  name=\"callback\" value="+callback + "/>"+
			 			"<input type=\"hidden\" id=\"fileType\" name=\"fileType\" value=\""+fileType+"\"/>"+
			 			"<input type=\"hidden\" id=\"idname\" name=\"idname\" value=\""+idname+"\"/>"+
			 			 
			 			"<span id=\"upLable\"/>：" +"<input type=\"file\" name=\"upload\" id=\"uploadP\"/>"+
			 			
						 "<input type=\"button\" onclick=\"uploadFile('"+fileType+"');\"   value=\"上传\"/>"+
						 "<input type=\"button\" onclick=\"clo();\"   value=\"关闭\"/>"+
						 "<input type=\"button\" id=\"picuplBut\" onclick=\"togWHtext();\"   value=\"修改图片大小\"/>"+
			 "<div id=\"whdivupl\">" +
			 "标准图高度:<input type=\"text\" id=\"imgH\" name=\"imgH\" value=\""+imgH+"\"/>" +
			 		"<br>"+
			 "标准图宽度:<input type=\"text\" id=\"imgW\" name=\"imgW\" value=\""+imgW+"\"/>" +
			 		"<br>" ;
			if((sImgH != '' && sImgH  != undefined ) ||  (sImgW != '' && sImgW != undefined)){
				mydom+= 
					"缩略图高度:" +
					"<input type=\"text\" id=\"sImgH\" name=\"sImgH\" value=\""+sImgH+"\"/>" +
							"<br>"+
				  "缩略图宽度:<input type=\"text\" id=\"sImgW\" name=\"sImgW\" value=\""+sImgW+"\"/>" +
				  		"<br>" ;
			}
			
		//删除 <img id=\"previewImg\"/> ,此处没有用到呈现,在上传完成后,返回url地址即可
		//	mydom+=  "</div>"+
		//	 "</form><div id=\"upmeDiv\" style=\"left: 125px;top: 60px;\"><span id=\"uphistory\"></span><img id=\"previewImg\"/></div>"+
			
			mydom+=  
				"</div>"+
			 "</form>" +
			 "<div id=\"upmeDiv\" style=\"left: 125px;top: 60px;\">" +
			 "<span id=\"uphistory\"/>" +
			 "</div>"+
			 "<iframe name=\"uploadIframe\" frameborder=0  height=0 width=0></iframe>" +
			 "</div>";
			
			
	 if($("#sampleUW").attr("class")!=undefined){
	 	if($("#uploadP").val() != ""){
		 	$("#uphistory").html("<font color=\"red\">你之前上传的文件是：</font>"+$("#uploadP").val());
		 	$("#uploadP").val("");
	 	}
	 	$("#imgH").val(imgH);
	 	$("#imgW").val(imgW);
	 	$("#fileType").val(fileType);
	 	$("#idname").val(idname);
		resizeWin('sampleUW','图片上传');
	 }else{
		 $("body").append(mydom);
		 resizeWin('sampleUW','图片上传');
	 }
	 dilogic(fileType);
}
function resizeWin(sw,tit){
	$('#'+sw).window({
					title: tit,
					width: 530,
					modal: false,
					shadow: false,
					closed: false,
					height: 175
		 });
}

function dilogic(fileType){
	 if(fileType == "pic"){
	 	 $("#whdivupl").hide();
		 $('#picuplBut').show();
	 	 $("#upLable").html("&nbsp;&nbsp;&nbsp;图片");
	 }else if(fileType == "video"){
	 	 $("#whdivupl").hide();
	 	 $('#picuplBut').hide();
	 	
	 	 $("#upLable").html("视频文件");
	 	 $("#previewImg").remove();
	 }else if(fileType=="flash"){
	 	 $("#whdivupl").hide();
	 	 $('#picuplBut').hide();
	 	
	 	 $("#upLable").html("flash文件");
	 	 $("#previewImg").remove();
	 }else{//if(fileType=="file"){
	 	 $("#whdivupl").hide();
	 	 $('#picuplBut').hide();
	 
	 	 $("#upLable").html("文件");
	 	 $("#previewImg").remove();
	 }
}
function clo(){
	 $("#sampleUW").window("close");
}
function messgeDis(idname,flag,ft,msg,murl,surl){
	if(flag == "T"){
		 $.messager.alert("上传结果",msg, "info");
		 $("#"+idname).val(murl);
		 if(ft == "pic"){
			 $("#previewImg").attr("src",murl);
		 }
	}else{
		sampleErrorMsg(msg);
	}
}
function togWHtext(){
	$("#whdivupl").toggle();
}
function sampleErrorMsg(msg){
		$.messager.alert("错误提示",msg, "error");
}

function uploadFile(fileType){
	var uploadP = $("#uploadP");
	if(uploadP.val() == null ||  $.trim(uploadP.val()).length == 0){
		sampleErrorMsg("请选择要上传的文件!");
		return;
	}
	document.getElementById("uploadMedia").submit();
}